<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
    
     <div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="formId">
				<input id="treeId" name="moduleId" type="hidden" th:value="${projectCaseModule.moduleId}"/>
				<input id="projectId" name="projectId" type="hidden" th:value="${projectCaseModule.projectId}"/>
				<input id="planId" name="planId" type="hidden" th:value="${planId}"/>
					<div class="select-list">
						<ul>
							<li>
								用例名称：<input type="text" name="caseName" />
							</li>
							<li>
								用例编号：<input type="text" name="caseSign"/>
							</li>
							<li>
								模块：
								<input type="text" style="width:150px;" onclick="selectModuleTree()" id="treeName" readonly="true" value=""/>
							</li>

							<li>
								用例类型：
								<select name="caseType" style="width:150px;" th:with="type=${@dict.getType('testmanagmt_case_type')}">
									<option value="">所有</option>
									<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
								</select>
							</li>

							<li>
							    <label style="vertical-align:middle;height:25px">计划用例：</label>
								<input type="checkbox" name="flag" style="width:20px;height:20px;cursor: pointer;"/>								
							</li>
							
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm" onclick="resetForm()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			
			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table" data-mobile-responsive="true" style="table-layout:fixed"></table>
			</div>
		</div>
	</div>
    <div th:include="include :: footer"></div>
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('testmanagmt:projectPlan:edit')}]];
        var removeFlag = [[${@permission.hasPermi('testmanagmt:projectPlan:remove')}]];
        var prefix = ctx + "testmanagmt/projectPlanCase";
        var modulePrefix = ctx + "testmanagmt/projectCaseModule";

        $(function() {			
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
				exportUrl: prefix + "/export",
                modalName: "测试用例",
				search: false,
				queryParams: function(params) {
	            	return {
	        			// 传递参数查询参数
	                    pageSize:       params.limit,
	                    pageNum:        params.offset / params.limit + 1,
	                    searchValue:    params.search,
	                    orderByColumn:  params.sort,
	                    isAsc:          params.order,
	                    planId:         $('#planId').val(),
	                    projectId:      $('#projectId').val()
	        		};
				},
		        showExport: false,
                columns: [{
                	field : 'flag',
					checkbox : true,
					formatter: function (value, row, index) {
					        return {
					            checked : row.flag//设置选中
					        };
					}
		        },
				{
					field : 'caseId', 
					title : '测试用例ID',
					sortable: true,
					visible: false
				},
				{
					field : 'planCaseId', 
					title : '测试计划用例ID',
					visible: false
				},
				{
					field : 'planId', 
					title : '测试计划ID',
					visible: false
				},
				{
					field : 'priority',
					title : '执行优先级',
					width : '10%',
					editable : {
						type : 'text',
						title : '执行优先级',
						emptytext : "0",
						validate : function(value) {
							if (isNaN(value)) return '优先级必须是数字';
	                        if (!(/(^[1-9]\d*$)/.test(value))) return '优先级必须是正整数';
							if (value.length > 8) return '优先级不能超过8个字符';
						}
					}
				}, 
				{
					field : 'projectCaseModule.moduleName', 
					title : '模块名称',
					width : '15%',
					class : 'myTDLengthHidden'
				},
				{
					field : 'caseSign', 
					title : '用例编号',
					sortable: true,
					width : '12%'
				},
				{
					field : 'caseName', 
					title : '用例名称',
					width : '26%',
					class : 'myTDLengthHidden',
                    formatter: function(value, row, index) {
                    	return $.table.tooltip(value);
                    }
				},
				{
					field : 'caseType', 
					title : '用例类型',
					width : '10%',
					class : 'myTDLengthHidden',
		        	formatter: function (value, row, index) {
		    		    if (row.caseType == 0) {
		        			return 'HTTP接口';
		        		} else if(row.caseType == 1){
		        			return 'Web UI';
		        		} else if(row.caseType == 2){
		        			return 'API驱动';
		        		} else if(row.caseType == 3){
		        			return '移动端';
		        		}else{
		        			return '未知类型';
		        		}
		        	}
				},
				{
					field : 'failcontinue', 
					title : '失败处理',
					width : '12%',
					class : 'myTDLengthHidden',
		        	formatter: function (value, row, index) {
		    		    if (row.failcontinue == 0) {
		        			return '后续步骤中断';
		        		} else if(row.failcontinue == 1){
		        			return '后续步骤继续';
		        		} else{
		        			return '非法数据';
		        		}
		        	}
				},
				{
					field : 'createBy', 
					title : '创建者',
					visible: false
				},
				{
					field : 'createTime', 
					title : '创建时间',
					visible: false
				},
				{
					field : 'updateBy', 
					title : '更新者',
					visible: false
				},
				{
					field : 'updateTime', 
					title : '更新时间',
					sortable: true,
					visible: false
				},
				{
					field : 'remark', 
					title : '备注',
					width : '15%',
					class : 'myTDLengthHidden',
                    formatter: function(value, row, index) {
                    	return $.table.tooltip(value);
                    }
				}],
				onEditableSave: function (field, row, oldValue, $el) {
					$.operate.saveJsonUnBack(prefix + "/edit", JSON.stringify(row));	
	            }
            };
            $.table.init(options);
        });
	    
        /*添加选择的用例到测试计划中*/
	    function submitHandler(){
	    	var rows = $.map($('#bootstrap-table').bootstrapTable('getData'), function (row) {
    	        return row;
    	    });
	    	
     		$.modal.confirm("确认保存您选择的用例到计划中吗?", function() {
				$.operate.saveJsonUnBack(prefix + "/savePlanCase", JSON.stringify(rows));
    		});
        	
	    }
	    
	    /*添加项目中所有的用例到测试计划中*/
	    function submitHandlerAll(){
     		$.modal.confirm("确认保存查询用例集合到计划中吗?", function() {
            	var config = {
            	        url: prefix + "/savePlanAllCase",
            	        type: "post",
            	        dataType: "json",
            	        data: $('#formId').serialize(),
            	        beforeSend: function () {
            	        	$.modal.loading("正在处理中，请稍后...");
            	        	$.modal.disable();
            	        },
            	        success: function(result) {
                        	if (result.code == web_status.SUCCESS) {
                            	$.modal.msgSuccess(result.msg);
                        		$.table.refresh();
                            } else {
                            	$.modal.alertError(result.msg);
                            }
                            $.modal.enable();
                            $.modal.closeLoading();
            	        }
            	    };
            	  $.ajax(config);
    		});
        	
	    }
	    
		/*查询条件选择用例模块*/
		function selectModuleTree() {
			var projectId=$("#projectId").val();
			var moduleId=$("#treeId").val();
			if(projectId==""){
				$.modal.alertError("未检查到计划项目");
			}else{
				if(moduleId==""){
					moduleId=projectId;
				}
				var options = {
						title: '模块选择',
						width: "380",
						url: modulePrefix + "/selectProjectCaseModuleTree/" + moduleId,
						callBack: doSubmit
					};
					$.modal.openOptions(options);
			}
		}
		
		function doSubmit(index, layero){
			var body = layer.getChildFrame('body', index);
   			$("#treeId").val(body.find('#treeId').val());
   			$("#treeName").val(body.find('#treeName').val());
   			layer.close(index);
		}
		
		function resetForm(){
			$("#treeId").val("");
			$.form.reset();
		}
    </script>
</body>
</html>